package com.wuye.basic.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wuye.basic.domain.dto.WyBalconyDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuye.common.annotation.Log;
import com.wuye.common.core.controller.BaseController;
import com.wuye.common.core.domain.AjaxResult;
import com.wuye.common.enums.BusinessType;
import com.wuye.basic.domain.WyBalcony;
import com.wuye.basic.service.IWyBalconyService;
import com.wuye.common.utils.poi.ExcelUtil;
import com.wuye.common.core.page.TableDataInfo;

/**
 * 楼座Controller
 * 
 * @author avalon
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/basic/balcony")
@Slf4j
public class WyBalconyController extends BaseController
{
    @Autowired
    private IWyBalconyService wyBalconyService;

    /**
     * 查询楼座列表
     */
    @PreAuthorize("@ss.hasPermi('basic:balcony:list')")
    @GetMapping("/list")
    public TableDataInfo list(WyBalcony wyBalcony)
    {
        startPage();
        List<WyBalcony> list = wyBalconyService.selectList(wyBalcony);
        return getDataTable(list);
    }

    /**
     * 导出楼座列表
     */
    @PreAuthorize("@ss.hasPermi('basic:balcony:export')")
    @Log(title = "楼座", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyBalcony wyBalcony)
    {
        List<WyBalcony> list = wyBalconyService.selectWyBalconyList(wyBalcony);
        ExcelUtil<WyBalcony> util = new ExcelUtil<WyBalcony>(WyBalcony.class);
        util.exportExcel(response, list, "楼座数据");
    }

    /**
     * 获取楼座详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:balcony:query')")
    @GetMapping(value = "/{balconyId}")
    public AjaxResult getInfo(@PathVariable("balconyId") Long balconyId)
    {
        return success(wyBalconyService.selectBybalconyId(balconyId));
    }

    /**
     * 新增楼座
     */
    @PreAuthorize("@ss.hasPermi('basic:balcony:add')")
    @Log(title = "楼座", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WyBalconyDTO wyBalconyDTO)
    {
        return toAjax(wyBalconyService.insertBalcony(wyBalconyDTO));
    }

    /**
     * 修改楼座
     */
    @PreAuthorize("@ss.hasPermi('basic:balcony:edit')")
    @Log(title = "楼座", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyBalconyDTO wyBalconyDTO)
    {
        return toAjax(wyBalconyService.updateInfo(wyBalconyDTO));
    }

    /**
     * 删除楼座
     */
    @PreAuthorize("@ss.hasPermi('basic:balcony:remove')")
    @Log(title = "楼座", businessType = BusinessType.DELETE)
	@DeleteMapping("/{balconyIds}")
    public AjaxResult remove(@PathVariable Long[] balconyIds)
    {
        log.info("删除楼座");
        List<Long> list = Arrays.asList(balconyIds);
        return toAjax(wyBalconyService.removeByIdsAndDTO(list));
    }
}
